package com.heima.schedule.feign;

import com.heima.apis.task.ITaskClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author ybw
 * @version 1.0
 * @date 2021/12/17 18:16
 */
@RestController
public class ScheduleFeignClient implements ITaskClient {
  @Autowired private TaskService taskService;
  /**
   * 新增定时发布任务
   *
   * @param task
   * @return
   */
  @Override
  @PostMapping("/api/v1/task/add")
  public ResponseResult addTask(@RequestBody Task task) {
    return ResponseResult.okResult(taskService.addTask(task));
  }

  /**
   * 消费定时任务
   *
   * @param type
   * @param priority
   * @return
   */
  @Override
  @GetMapping("/api/v1/task/poll/{type}/{priority}")
  public ResponseResult pollTask(
      @PathVariable("type") Integer type, @PathVariable("priority") Integer priority) {
    ResponseResult result = ResponseResult.okResult(taskService.pollTask(type, priority));
    return result;
  }
}
